package com.xc.common.tool;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component
@Lazy(false)
public class BeanAid implements ApplicationContextAware {
	private static ApplicationContext applicationContext ;
	@SuppressWarnings("static-access")
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}
	@SuppressWarnings("unchecked")
	public static<T> T getBean(String beanName){
		T bean = (T) applicationContext.getBean(beanName);
		return bean;
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static<T> T getBean(Class clazz){
		T bean = (T) applicationContext.getBean(clazz);
		return bean;
	}
}
